<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ include file="/static/include/taglib.jsp" %>
<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>后台管理--菜单列表</title>
    <link href="${ctxStatic}/layui/css/layui.css" rel="stylesheet"/>
    <link href="${ctxStatic}/css/kpiui.css" rel="stylesheet"/>
    <script src="${ctxStatic}/js/jquery-1.8.3.min.js?v=2.0" type="text/javascript"></script>
    <script src="${ctxStatic}/layui/layui.all.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/common.js" type="text/javascript"></script>
    <script src="${ctxStatic}/js/attendance/atttb.js" type="text/javascript"></script>
    <style>

        #plugin {

            margin-top: -20px;

        }

    </style>
</head>
<body>

<form class="layui-form" action="">
    <div class="layui-form-item">

        <div class="layui-input-block">
            <input type="radio" lay-filter="erweima" name="sex" value="1" title="上月" checked="">
            <input type="radio" lay-filter="erweima" name="sex" value="2" onchange="changeType(this)" title="当月">
        </div>
    </div>
</form>
<div class="mess">
    <h1 style="text-align: center;
    color: white;
    margin-top: 20px;">当前没有公示信息</h1>
</div>
<iframe id="fileData" style="width:98%;height: 90%;margin-left: 10px"></iframe>
</body>

<script>


    $(function () {


        layui.use(['form'], function () {

            var form = layui.form
            form.render();
            form.on('radio(erweima)', function (data) {

                getData(data.value);
            });


        })
        getData(1);


    })

    function getPreMonth() {

        var year = new Date().getFullYear(); //获取当前日期的年份
        var month = new Date().getMonth() + 1; //获取当前   日期的月份
        var day = new Date().getDate(); //获取当前日期的日
        var days = new Date(year, month, 0);
        days = days.getDate(); //获取当前日期中月的天数
        var year2 = year;
        var month2 = parseInt(month) - 1;
        if (month2 == 0) {//如果是1月份，则取上一年的12月份
            year2 = parseInt(year2) - 1;
            month2 = 12;
        }
        var day2 = day;
        var days2 = new Date(year2, month2, 0);
        days2 = days2.getDate();
        if (day2 > days2) {//如果原来日期大于上一月的日期，则取当月的最大日期。比如3月的30日，在2月中没有30
            day2 = days2;
        }
        // if (month2 < 10) {
        //     month2 = '0' + month2;//月份填补成2位。
        // }
        var t2 = year2 + '-' + month2 + '-' + day2;
        return new Date(t2);
    }

    function getData(type) {

        var year = new Date().getFullYear();
        var month = new Date().getMonth() + 1;
        if (type == 1) {

            year = getPreMonth().getFullYear();
            month = getPreMonth().getMonth() + 1;


        }
        $.ajax({
            type: "POST",
            url: "showPDF",
            data: {
                year: year,
                month: month,
                type: type
            },
            beforeSend: function (XHR) {

            },
            success: function (data) {
                console.log('pdf url--' + data)
                if (data != '') {
                    $('#fileData').attr('src', data);
                    $('.mess').hide();
                    $('.pageInfo').show();
                    $('#fileData').show();
                    $('#plugin').css('margin-top', -20)

                }
                else {
                    $('.mess').show();
                    $('.pageInfo').hide();
                    $('#fileData').hide();
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });

    }


</script>
</html>
